delete an object method to IDigBioStorage


In [1]:
from __future__ import division, absolute_import, print_function

In [2]:
from idb.postgres_backend import apidbpool
from idb.helpers.logging import idblogger

In [3]:
from idb.helpers.storage import IDigBioStorage

In [4]:
store = IDigBioStorage()

In [5]:
#bucket = store.get_bucket("idigbio-images-prod-fullsize")

In [6]:
newkey = store.get_key('ABC123.png', 'idigbio-images-prod-fullsize')

In [17]:
## upload a sample image, then delete it
myfilename = '/home/dstoner/Documents/ABC123.png'

with open(myfilename) as f:
    k = store.upload(newkey, f, content_type="image/png", public=True)

In [18]:
k.bucket


Out[18]:
<Bucket: idigbio-images-prod-fullsize>

In [19]:
k.name


Out[19]:
'ABC123.png'

In [20]:
k.exists()


Out[20]:
True

In [21]:
k.delete()


Out[21]:
<Key: idigbio-images-prod-fullsize,ABC123.png>

In [22]:
k.bucket


Out[22]:
<Bucket: idigbio-images-prod-fullsize>

In [23]:
k.name


Out[23]:
'ABC123.png'

In [24]:
### after deleted, should be False
k.exists()


Out[24]:
False

Delete a list of recordset objects by uuid...

Not sure why we would want to do this.


In [25]:
from idb.postgres_backend.db import PostgresDB
idbmodel = PostgresDB()

In [26]:
bucket_name = 'idigbio-datasets-prod'
baseurl = 'http://api.idigbio.org/v1/recordsets/'

In [27]:
keys_to_delete = [
#"02fceae6-c71c-4db9-8b2f-e235ced6624a",
"04d9b721-259c-4d6b-b48f-2e23edf66c9f",
"11d3ad3b-38de-4709-8544-ec3c26d96607",
"15aa4812-aad2-4b26-a1d8-d4f8d79e6163",
"1eca069b-09e0-406d-9625-cb9c52e1e5cc",
"252a0a12-f114-4fb5-aa9a-678c523d6dcd",
"285a4be0-5cfe-4d4f-9c8b-b0f0f3571079",
"37d4d085-d8be-4826-9bc4-c6a36557fa70",
"7b0809fb-fd62-4733-8f40-74ceb04cbcac",
"91c5eec8-0cdc-4be2-9a99-a15ae5ec3edc",
"97e4947d-fce9-4019-9f86-c0d94c820269",
"9e103d5f-fc45-4375-b416-802659e6dc1b",
"a062eb42-d5c6-4332-8c88-64b4ac1af892",
"b7349341-c8e2-4628-be5f-77600ba730fa",
"cf641fbf-fa31-481a-993b-9204f2ee1884",
"da67ebd9-52de-444d-b114-e23c03111ac6",
"e5b0c46a-5eb6-4b94-9d4c-fb1000f534b0",
"e95396c4-1cac-4c9b-b461-5f21cd978fc6",
"ec248223-f277-4c02-b1fa-60056b5a689a",
"fc628e53-5fdf-4436-9782-bf637d812b48"
]

In [28]:
try_one = store.get_key_by_url(url=baseurl+"02fceae6-c71c-4db9-8b2f-e235ced6624a", idbmodel=idbmodel)

In [29]:
try_one


Out[29]:
<Key: idigbio-datasets-prod,328bee761b2aa6511dbb78f7356c835e>

In [30]:
try_one.delete()


Out[30]:
<Key: idigbio-datasets-prod,328bee761b2aa6511dbb78f7356c835e>

In [18]:
for each in keys_to_delete:
    obj_to_del = store.get_key_by_url(url=baseurl+each, idbmodel=idbmodel)
    obj_to_del.delete()

In [ ]: